import 'dart:async';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_learn_vi/src/bean/bean_train.dart';
import 'package:flutter_learn_vi/src/utils/toast_utils.dart';

/// 创建人： Created by zhaolong
/// 创建时间：Created by  on 2021/1/14.
///
/// 可关注公众号：我的大前端生涯   获取最新技术分享
/// 可关注网易云课堂：https://study.163.com/instructor/1021406098.htm
/// 可关注博客：https://blog.csdn.net/zl18603543572
///
/// 代码清单
///代码清单
class TrainApproveItemWidget extends StatefulWidget {
  final TrainApproveBean approveBean;
  final int index;
  final StreamController<int> streamController;

  TrainApproveItemWidget(this.approveBean, this.index, this.streamController);

  @override
  _TrainApproveItemWidgetState createState() => _TrainApproveItemWidgetState();
}

class _TrainApproveItemWidgetState extends State<TrainApproveItemWidget> {
  @override
  Widget build(BuildContext context) {
    return buildBodyWidget();
  }

  //每个子Item的布局构建
  Widget buildBodyWidget() {
    //水波纹点击事件监听
    return InkWell(
      //手指点击抬起时的回调
      onTap: () {
        //打开新的页面
        // NavigatorUtils.pushPage(
        //     context,
        //     TrainApproveDetaisPage(
        //       approveBean: widget.approveBean,
        //     ), callback: (value) {
        //   widget.streamController.add(0);
        // });
        ToastUtils.showToast("本版本暂不支持审批 请升级至最新版本App");
      },
      child: Container(
        padding: EdgeInsets.all(10),
        margin: EdgeInsets.only(top: 1.0),
        color: Colors.white,
        //线性布局左右排列
        child: Row(
          //主轴方向开始对齐 在这里是左对齐
          mainAxisAlignment: MainAxisAlignment.start,
          //交叉轴上开始对齐 在这里是顶部对齐
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            //左侧的图片
            buildLeftImage(),
            //右侧的文本区域
            buildRightTextArea(),
            Container(
              child: Icon(Icons.arrow_right),
            )
          ],
        ),
      ),
    );
  }

  ///左侧的图片区域
  Container buildLeftImage() {
    int approeStatues = widget.approveBean.approeStatues;
    String statuesStr = "";
    Color textColor = Colors.blueGrey;
    if (approeStatues == 0) {
      statuesStr = "等待审核中";
    } else if (approeStatues == 1) {
      statuesStr = "已通过";
      textColor = Colors.green;
    } else if (approeStatues == 2) {
      statuesStr = "已拒绝";
      textColor = Colors.red;
    } else if (approeStatues == 3) {
      statuesStr = "已撤消";
      textColor = Colors.orange;
    } else if (approeStatues == 4) {
      statuesStr = "待处理";
      textColor = Colors.red;
    }
    return Container(
      padding: EdgeInsets.only(left: 4, right: 4, top: 1, bottom: 1),
      alignment: Alignment.center,
      margin: EdgeInsets.only(right: 8, top: 6),
      decoration: BoxDecoration(
          color: textColor,
          borderRadius: BorderRadius.all(Radius.circular(4)),
          border: Border.all(color: Colors.blue)),
      child: Text(
        "${widget.index + 1} $statuesStr",
        style: TextStyle(fontSize: 10, color: Colors.white),
      ),
    );
  }

  ///右侧的文本区域
  Expanded buildRightTextArea() {
    return Expanded(
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        mainAxisSize: MainAxisSize.min,
        children: [
          Text(
            "${widget.approveBean.trainName}",
            softWrap: true,
            overflow: TextOverflow.ellipsis,
            maxLines: 3,
            style: TextStyle(fontSize: 16),
          ),
          SizedBox(
            height: 8,
          ),
          Text(
            "申请时间 ${widget.approveBean.commitTime}",
            softWrap: true,
            overflow: TextOverflow.ellipsis,
            maxLines: 3,
            style: TextStyle(fontSize: 12, color: Colors.black38),
          )
        ],
      ),
    );
  }
}
